/**    
 * @{#} QuestionDetailAdapter.java Create on 2014-5-30 下午7:18:09    
 *          
 * @author <a href="mailto:evan0502@qq.com">Evan</a>   
 * @version 1.0    
 */
package com.smiier.skin.adapter;

import java.util.ArrayList;
import java.util.HashMap;

import org.json.JSONArray;
import org.json.JSONObject;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Paint;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.HorizontalScrollView;
import android.widget.ImageView.ScaleType;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import cn.o.app.ui.OImageView;
import cn.o.app.ui.photo.PhotoActivity;
import cn.o.app.ui.photo.PhotoExtra;
import cn.o.app.util.OUtil;
import cn.skinapp.R;

import com.evan.common.adapter.BaseListAdapter;
import com.evan.common.connection.ConnectionCommon;
import com.evan.common.handler.RequestHandler;
import com.evan.common.handler.callback.HandlerCallback;
import com.lidroid.xutils.BitmapUtils;
import com.smiier.skin.ChatActivity;
import com.smiier.skin.CreateProjectCommentActivity;
import com.smiier.skin.DoctorDetailActivity;
import com.smiier.skin.LoginActivity;
import com.smiier.skin.QuestionDetailActivity;
import com.smiier.skin.ZhiliaofanganActivity;
import com.smiier.skin.constant.Constant;
import com.smiier.skin.intercept.RequestTaskIntercept;
import com.smiier.skin.util.GlobalSettings;
import com.smiier.skin.util.ShareUtil;
import com.smiier.skin.utils.CommonUtility;

@SuppressLint("InflateParams")
public class QuestionDetailAdapter extends BaseListAdapter {

	QuestionDetailActivity activity;

	protected BitmapUtils mBitmapUtils;

	public QuestionDetailAdapter(Activity activity, ArrayList<Object> array) {
		super(activity, array);
		this.activity = (QuestionDetailActivity) activity;
		mBitmapUtils = new BitmapUtils(activity);
	}

	class ViewHolder {
		TextView text_guanzhu_num, text_guanzhu_date, text_content,
				text_buwei_zhengzhuang, text_cost, text_create_date,
				text_jiedan_doctor, text_jieda_result, text_bingzhengtuiduan,
				text_buweixiuzheng, text_huanzhezishu_buwei,
				text_bingzhuangxiuzheng, text_huanzhezishu_bingzhuang,
				text_zhiliaocuoshi, text_comment_value, text_comment_type;
		LinearLayout ll_cost, ll_imgs, btn_jieda, ll_after_jiedan, ll_result,
				ll_btn_guanzhu_share, ll_buweixiuzheng, ll_bingzhuangxiuzheng,
				ll_status;
		RelativeLayout// rl_comment,
		ll_zhiliao_fangan;
		Button btn_guanzhu, btn_share, btn_zhiliaofangan, btn_huihuawenzhen,
				btn_comment;
		HorizontalScrollView hsv_imgs;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.widget.Adapter#getView(int, android.view.View,
	 * android.view.ViewGroup)
	 */
	@Override
	public View getView(int position, View convertView, ViewGroup root) {
		// TODO Auto-generated method stub
		ViewHolder viewHolder = null;
		if (CommonUtility.isNull(convertView)) {
			convertView = inflater.inflate(R.layout.item_question_detail, null);
			viewHolder = new ViewHolder();
			viewHolder.text_guanzhu_num = (TextView) convertView
					.findViewById(R.id.text_guanzhu_num);
			viewHolder.text_guanzhu_date = (TextView) convertView
					.findViewById(R.id.text_guanzhu_date);
			viewHolder.text_content = (TextView) convertView
					.findViewById(R.id.text_content);
			viewHolder.text_buwei_zhengzhuang = (TextView) convertView
					.findViewById(R.id.text_buwei_zhengzhuang);
			viewHolder.text_cost = (TextView) convertView
					.findViewById(R.id.text_cost);
			viewHolder.text_create_date = (TextView) convertView
					.findViewById(R.id.text_create_date);
			viewHolder.ll_cost = (LinearLayout) convertView
					.findViewById(R.id.ll_cost);
			viewHolder.ll_imgs = (LinearLayout) convertView
					.findViewById(R.id.ll_imgs);
			viewHolder.btn_guanzhu = (Button) convertView
					.findViewById(R.id.btn_guanzhu);
			viewHolder.btn_comment = (Button) convertView
					.findViewById(R.id.btn_comment);
			viewHolder.btn_share = (Button) convertView
					.findViewById(R.id.btn_share);
			viewHolder.btn_jieda = (LinearLayout) convertView
					.findViewById(R.id.ll_jieda);
			viewHolder.ll_after_jiedan = (LinearLayout) convertView
					.findViewById(R.id.ll_after_jiedan);
			viewHolder.ll_result = (LinearLayout) convertView
					.findViewById(R.id.ll_result);
			viewHolder.ll_buweixiuzheng = (LinearLayout) convertView
					.findViewById(R.id.ll_buweixiuzheng);
			viewHolder.ll_bingzhuangxiuzheng = (LinearLayout) convertView
					.findViewById(R.id.ll_bingzhuangxiuzheng);
			viewHolder.ll_status = (LinearLayout) convertView
					.findViewById(R.id.ll_status);

			viewHolder.text_jiedan_doctor = (TextView) convertView
					.findViewById(R.id.doctor_name);
			viewHolder.text_jieda_result = (TextView) convertView
					.findViewById(R.id.text_jieda_result);
			viewHolder.text_bingzhengtuiduan = (TextView) convertView
					.findViewById(R.id.text_bingzhengtuiduan);
			viewHolder.text_buweixiuzheng = (TextView) convertView
					.findViewById(R.id.text_buweixiuzheng);
			viewHolder.text_huanzhezishu_buwei = (TextView) convertView
					.findViewById(R.id.text_huanzhezishu_buwei);
			viewHolder.text_bingzhuangxiuzheng = (TextView) convertView
					.findViewById(R.id.text_bingzhuangxiuzheng);
			viewHolder.text_huanzhezishu_bingzhuang = (TextView) convertView
					.findViewById(R.id.text_huanzhezishu_bingzhuang);
			viewHolder.text_zhiliaocuoshi = (TextView) convertView
					.findViewById(R.id.text_zhiliaocuoshi);
			viewHolder.btn_zhiliaofangan = (Button) convertView
					.findViewById(R.id.btn_zhiliaofangan);
			viewHolder.btn_huihuawenzhen = (Button) convertView
					.findViewById(R.id.btn_huihuawenzhen);
			viewHolder.ll_zhiliao_fangan = (RelativeLayout) convertView
					.findViewById(R.id.ll_zhiliao_fangan);
			viewHolder.hsv_imgs = (HorizontalScrollView) convertView
					.findViewById(R.id.hsv_imgs);

			viewHolder.text_comment_value = (TextView) convertView
					.findViewById(R.id.text_comment_value);
			viewHolder.text_comment_type = (TextView) convertView
					.findViewById(R.id.text_comment_type);
			// viewHolder.rl_comment = (RelativeLayout) convertView
			// .findViewById(R.id.rl_comment);
			viewHolder.ll_btn_guanzhu_share = (LinearLayout) convertView
					.findViewById(R.id.ll_btn_guanzhu_share);

			viewHolder.btn_jieda.setOnClickListener(listener);
			viewHolder.btn_share.setOnClickListener(listener);
			viewHolder.btn_zhiliaofangan.setOnClickListener(listener);
			viewHolder.btn_huihuawenzhen.setOnClickListener(listener);
			viewHolder.btn_comment.setOnClickListener(listener);
			viewHolder.text_jiedan_doctor.setOnClickListener(listener);
			CommonUtility.setViewHolderTag(convertView, viewHolder);
		} else {
			viewHolder = (ViewHolder) CommonUtility
					.getViewHolderTag(convertView);
		}
		try {
			JSONObject object = (JSONObject) getItem(position);
			JSONObject question = object.getJSONObject("Question");
			JSONObject jiedan_doctor = object.getJSONObject("Doctor_User");
			String qid = question.getString("Qid");
			viewHolder.text_jiedan_doctor.setTag(jiedan_doctor);
			viewHolder.btn_share.setTag(question);
			viewHolder.btn_comment.setVisibility(View.GONE);
			int is_follow = object.getInt("Is_Follow");
			if (is_follow == 1) {
				viewHolder.btn_guanzhu.setText("已收藏");
			}
			viewHolder.btn_guanzhu.setTag(qid);
			viewHolder.btn_guanzhu.setOnClickListener(listener);
			viewHolder.btn_guanzhu.setTag(R.id.tag_obj, position);

			viewHolder.text_guanzhu_date.setText(CommonUtility.formatDate(
					question.getString("CreateTime"), 0, 10));
			viewHolder.text_content.setText(question.getString("Content"));
			StringBuilder sbBuweiZhengzhuang = new StringBuilder();
			String part = CommonUtility.convertJSONArray2String(
					question.getJSONArray("Part"), ",");
			if (!CommonUtility.isNull(part)) {
				sbBuweiZhengzhuang.append(part);
			}
			String symptom = CommonUtility.convertJSONArray2String(
					question.getJSONArray("Symptom"), ",");
			if (!CommonUtility.isNull(part) && !CommonUtility.isNull(symptom)) {
				sbBuweiZhengzhuang.append("  |  ").append(
						CommonUtility.convertJSONArray2String(
								question.getJSONArray("Symptom"), ","));
			}
			if (CommonUtility.isNull(sbBuweiZhengzhuang)) {
				viewHolder.text_buwei_zhengzhuang.setVisibility(View.GONE);
			} else {
				viewHolder.text_buwei_zhengzhuang.setVisibility(View.VISIBLE);
				viewHolder.text_buwei_zhengzhuang.setText(sbBuweiZhengzhuang
						.toString());
			}
			int followCount = object.getInt("FollowerCount");
			viewHolder.text_guanzhu_num.setText(followCount + "");
			int cost = question.getInt("Cost");
			int status = question.getInt("Status");

			if (CommonUtility.isNull(GlobalSettings.sUser)) {
				viewHolder.ll_btn_guanzhu_share.setVisibility(View.GONE);
			} else {
				viewHolder.ll_btn_guanzhu_share.setVisibility(View.VISIBLE);
			}

			if (!CommonUtility.isNull(GlobalSettings.sUser)) {
				// viewHolder.ll_btn_guanzhu_share.setVisibility(View.GONE);
				if (GlobalSettings.sUser.Uid == question.getInt("Uid")) {
					viewHolder.btn_guanzhu.setVisibility(View.GONE);
				} else {
					viewHolder.btn_guanzhu.setVisibility(View.VISIBLE);
				}
			}
			/**
			 * status 问题当前状态 0 创建完成-指定医生（尚未编辑问题）， 1 发起问题（直接创建问题时的状态）， 2 已接单， 3
			 * 已下诊断
			 */
			if (status == 1) {
				if (CommonUtility.isDoctor()) {
					viewHolder.btn_jieda.setVisibility(View.VISIBLE);
					viewHolder.btn_jieda.setTag(qid);
					viewHolder.btn_jieda.setTag(R.id.tag_obj, position);
					viewHolder.btn_jieda.setTag(R.id.tag_obj1,
							viewHolder.ll_zhiliao_fangan);
				}
				viewHolder.ll_after_jiedan.setVisibility(View.GONE);
				viewHolder.ll_result.setVisibility(View.GONE);
				viewHolder.ll_zhiliao_fangan.setVisibility(View.GONE);
			} else if (status == 2 || status == 3) {
				viewHolder.btn_jieda.setVisibility(View.GONE);
				viewHolder.ll_after_jiedan.setVisibility(View.VISIBLE);
				if (status == 2) {
					viewHolder.ll_result.setVisibility(View.GONE);
					if (CommonUtility.isDoctor()
							&& CommonUtility.isMineQuestion(question)) {
						viewHolder.ll_zhiliao_fangan
								.setVisibility(View.VISIBLE);
						viewHolder.btn_zhiliaofangan.setTag(object);
						viewHolder.btn_huihuawenzhen.setTag(object);
					} else {
						viewHolder.ll_zhiliao_fangan.setVisibility(View.GONE);
					}
				} else {
					viewHolder.ll_result.setVisibility(View.VISIBLE);
					JSONObject answer = object.getJSONObject("Answer");
					if (!CommonUtility.isNull(GlobalSettings.sUser)
							&& question.getInt("Uid") == GlobalSettings.sUser.Uid
							&& question.getInt("Is_Appraise") == 0) {
						viewHolder.btn_comment.setVisibility(View.VISIBLE);
						viewHolder.btn_comment.setTag(object);
					} else {
						viewHolder.btn_comment.setVisibility(View.GONE);
					}

					viewHolder.text_bingzhengtuiduan.setText(answer
							.getString("Disease_Inference"));
					viewHolder.text_jieda_result.setText(answer
							.getString("Malady"));

					String buwei_xiugzheng = CommonUtility
							.convertJSONArray2String(
									answer.getJSONArray("Part"), ",");
					if (CommonUtility.isNull(buwei_xiugzheng)) {
						viewHolder.ll_buweixiuzheng.setVisibility(View.GONE);
					} else {
						viewHolder.ll_buweixiuzheng.setVisibility(View.VISIBLE);
						viewHolder.text_buweixiuzheng.setText(buwei_xiugzheng);
						viewHolder.text_huanzhezishu_buwei.getPaint().setFlags(
								Paint.STRIKE_THRU_TEXT_FLAG);
					}

					String buwei_zishu = CommonUtility.convertJSONArray2String(
							question.getJSONArray("Part"), ",");
					if (CommonUtility.isNull(buwei_zishu)) {
						viewHolder.text_huanzhezishu_buwei
								.setVisibility(View.GONE);
					} else {
						viewHolder.text_huanzhezishu_buwei
								.setVisibility(View.VISIBLE);
						viewHolder.text_huanzhezishu_buwei.setText("患者自述："
								+ buwei_zishu);
					}

					String bingzhuang = CommonUtility.convertJSONArray2String(
							answer.getJSONArray("Symptom"), ",");
					if (!CommonUtility.isNull(bingzhuang)) {
						viewHolder.text_bingzhuangxiuzheng.setText(bingzhuang);
						viewHolder.ll_bingzhuangxiuzheng
								.setVisibility(View.VISIBLE);
						viewHolder.text_huanzhezishu_bingzhuang.getPaint()
								.setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
					} else {
						viewHolder.ll_bingzhuangxiuzheng
								.setVisibility(View.GONE);
					}

					String bingzhuang_zishu = CommonUtility
							.convertJSONArray2String(
									question.getJSONArray("Symptom"), ",");
					if (CommonUtility.isNull(bingzhuang_zishu)) {
						viewHolder.text_huanzhezishu_bingzhuang
								.setVisibility(View.GONE);
					} else {
						viewHolder.text_huanzhezishu_bingzhuang
								.setVisibility(View.VISIBLE);
						viewHolder.text_huanzhezishu_bingzhuang.setText("患者自述："
								+ bingzhuang_zishu);
					}
					JSONArray treatments = answer.getJSONArray("Treatments");
					StringBuilder sb = new StringBuilder();
					for (int i = 0; i < treatments.length(); i++) {
						JSONObject o = treatments.getJSONObject(i);
						String drug = o.getString("Drug");
						String advice = o.getString("Advice");
						sb.append(o.getString("Drug"));
						if (!CommonUtility.isNull(drug)
								&& !CommonUtility.isNull(advice)) {
							sb.append(" | ");
						}
						sb.append(advice);
						if (i < treatments.length() - 1) {
							sb.append("\n");
						}
					}
					viewHolder.text_zhiliaocuoshi.setText(sb);

					if (question.getInt("Is_Appraise") == 1) {
						// viewHolder.rl_comment.setVisibility(View.VISIBLE);
						JSONObject comment = object.getJSONObject("Appraise");
						viewHolder.text_comment_value.setText(comment
								.getString("Content"));
						int level = comment.getInt("Level");
						if (level == 1) {
							viewHolder.text_comment_type
									.setBackgroundResource(R.drawable.tag_comment_bad);
							viewHolder.text_comment_type.setText("差评");
							viewHolder.text_comment_type
									.setTextColor(0xff858585);
						} else if (level == 2) {
							viewHolder.text_comment_type
									.setBackgroundResource(R.drawable.tag_comment_middle);
							viewHolder.text_comment_type.setText("中评");
							viewHolder.text_comment_type
									.setTextColor(0xffffc02a);
						} else if (level == 3) {
							viewHolder.text_comment_type
									.setBackgroundResource(R.drawable.tag_comment_good);
							viewHolder.text_comment_type.setText("好评");
							viewHolder.text_comment_type
									.setTextColor(0xff91d2b9);
						}
					} else {
						// 如果问题解答医生是当前医生则显示编辑
						/*
						 * if (!CommonUtility.isNull(GlobalSettings.sUser) &&
						 * answer.getInt("Doctor_Uid") ==
						 * GlobalSettings.sUser.Uid) {
						 * viewHolder.ll_edit_zhiliaofangan
						 * .setVisibility(View.VISIBLE);
						 * viewHolder.ll_edit_zhiliaofangan.setTag(object); }
						 * else { viewHolder.ll_edit_zhiliaofangan
						 * .setVisibility(View.GONE); }
						 */
						// viewHolder.rl_comment.setVisibility(View.GONE);
					}
				}

				StringBuilder sb = new StringBuilder();
				sb.append(jiedan_doctor.getString("Name"))
						.append("（")
						.append(CommonUtility.convertJSONArray2String(
								jiedan_doctor.getJSONArray("Professional"), ","))
						.append(" | ")
						.append(jiedan_doctor.getString("Hospital"))
						.append("）");
				SpannableStringBuilder builder = new SpannableStringBuilder(sb);
				// ForegroundColorSpan 为文字前景色，BackgroundColorSpan为文字背景色
				ForegroundColorSpan blueSpan = new ForegroundColorSpan(activity
						.getResources().getColor(R.color.border_blue));
				builder.setSpan(blueSpan, 0, sb.indexOf("（"),
						Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
				viewHolder.text_jiedan_doctor.setText(builder);
			}

			if (cost == 0) {
				viewHolder.ll_cost.setVisibility(View.GONE);
			} else {
				viewHolder.ll_cost.setVisibility(View.VISIBLE);
				viewHolder.text_cost.setText("悬赏解答：￥" + cost);
				viewHolder.text_create_date.setText("创建时间："
						+ CommonUtility.formatDate(
								question.getString("Cost_Time"), 11, 16));
			}
			viewHolder.text_content.setText(question.getString("Content"));

			if (CommonUtility.isDoctor() && CommonUtility.isCert()) {
				JSONArray pics = question.getJSONArray("Pic");
				viewHolder.ll_imgs.removeAllViews();
				if (pics.length() > 0) {
					viewHolder.hsv_imgs.setVisibility(View.VISIBLE);
					String[] picStrs = new String[pics.length()];
					for (int i = 0; i < pics.length(); i++) {
						OImageView layout = new OImageView(activity);
						layout.setIsRoundRect(true);
						layout.setId(R.id.imgLayout_show);
						layout.setScaleType(ScaleType.CENTER_CROP);
						LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
								(int) OUtil.dp2px(activity, 70),
								(int) OUtil.dp2px(activity, 70));
						layoutParams.setMargins(0, 0,
								(int) OUtil.dp2px(activity, 8), 0);
						layout.setLayoutParams(layoutParams);

						final String path = pics.getString(i) + Constant.IMG_TH;
						mBitmapUtils.display(layout,
								GlobalSettings.SERVER_IMG_URL + path);
						viewHolder.ll_imgs.addView(layout);
						// layout.setImageFileTag(pics.getString(i)
						// + Constant.IMG_SRC);
						layout.setOnClickListener(listener_img);
						layout.setTag(i);
						layout.setTag(R.id.tag_obj, picStrs);
						picStrs[i] = ConnectionCommon.getInstance().REQUEST_PIC_PATH
								+ pics.getString(i) + Constant.IMG_SRC;

					}
				} else {
					viewHolder.hsv_imgs.setVisibility(View.GONE);
				}
			} else {
				viewHolder.hsv_imgs.setVisibility(View.GONE);
			}

			if (!CommonUtility.isDoctor() && status == 1) {
				viewHolder.ll_status.setVisibility(View.GONE);
			} else {
				viewHolder.ll_status.setVisibility(View.VISIBLE);
			}
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return convertView;
	}

	HashMap<String, Object> params;
	HashMap<String, Object> jieda_params;
	OnClickListener listener = new OnClickListener() {

		@Override
		public void onClick(final View view) {
			Intent intent;
			int id = view.getId();
			if (id == R.id.text_jiedan_doctor) {
				intent = new Intent(activity, DoctorDetailActivity.class);
				intent.putExtra(Constant.IDENTITY_KEY, view.getTag().toString());
				activity.startActivity(intent);
			} else if (id == R.id.btn_comment) {
				intent = new Intent(activity,
						CreateProjectCommentActivity.class);
				intent.putExtra(Constant.IDENTITY_KEY, view.getTag().toString());
				activity.startActivity(intent);
			} else if (id == R.id.btn_zhiliaofangan) {
				JSONObject o = (JSONObject) view.getTag();
				if (!CommonUtility.isNull(GlobalSettings.sUser)
						&& !CommonUtility.isNull(o)) {
					intent = new Intent(activity, ZhiliaofanganActivity.class);
					intent.putExtra(Constant.IDENTITY_KEY, o.toString());
					activity.startActivity(intent);
				} else {
					activity.startActivity(new Intent(activity,
							LoginActivity.class));
				}
			} else if (id == R.id.btn_huihuawenzhen) {
				if (!CommonUtility.isNull(GlobalSettings.sUser)) {
					JSONObject o = (JSONObject) view.getTag();
					intent = new Intent(activity, ChatActivity.class);
					intent.putExtra(Constant.IDENTITY_KEY, o.toString());
					activity.startActivity(intent);
				} else {
					activity.startActivity(new Intent(activity,
							LoginActivity.class));
				}
			}
			/*
			 * else if (id == R.id.ll_edit_zhiliaofangan) { Object t =
			 * view.getTag(); if (!CommonUtility.isNull(t)) { intent = new
			 * Intent(activity, ZhiliaofanganActivity.class);
			 * intent.putExtra(Constant.IDENTITY_KEY, t.toString());
			 * activity.startActivity(intent); } }
			 */
			else if (id == R.id.btn_share) {
				if (!CommonUtility.isNull(GlobalSettings.sUser)) {
					JSONObject question = (JSONObject) view.getTag();
					try {
						String url = GlobalSettings.SERVER_URL_TREATMENT
								+ "WeChat/MenuData/questionInfo/qid/"
								+ question.getString("Qid");
						StringBuilder sbBuweiZhengzhuang = new StringBuilder();
						String part = CommonUtility.convertJSONArray2String(
								question.getJSONArray("Part"), ",");
						if (!CommonUtility.isNull(part)) {
							sbBuweiZhengzhuang.append(part);
						}
						String symptom = CommonUtility.convertJSONArray2String(
								question.getJSONArray("Symptom"), ",");
						if (!CommonUtility.isNull(part)
								&& !CommonUtility.isNull(symptom)) {
							sbBuweiZhengzhuang.append("  |  ").append(
									CommonUtility.convertJSONArray2String(
											question.getJSONArray("Symptom"),
											","));
						}
						ShareUtil.share(activity, url, sbBuweiZhengzhuang,
								question.getString("Content"));
					} catch (Exception e) {
						e.printStackTrace();
					}
				} else {
					activity.startActivity(new Intent(activity,
							LoginActivity.class));
				}
			} else if (id == R.id.ll_jieda) {
				if (!CommonUtility.isNull(GlobalSettings.sUser)) {
					if (CommonUtility.isNull(jieda_params)) {
						jieda_params = new HashMap<String, Object>();
						jieda_params.put(Constant.PARAM_API, "Question.Set");
						jieda_params.put("Status", 2);
						jieda_params.put(Constant.PARAM_TOKEN,
								GlobalSettings.sToken);
						try {
							jieda_params.put("Doctor_Uid",
									GlobalSettings.sUser.Uid);
						} catch (Exception e) {
							// TODO: handle exception
							e.printStackTrace();
						}
					}
					jieda_params.put("qid", view.getTag());
					final int p = (Integer) view.getTag(R.id.tag_obj);
					RequestTaskIntercept.requestIntercept(activity,
							Constant.URL.REQUEST, new RequestHandler(activity,
									new HandlerCallback() {

										@Override
										public void callback(Object o) {
											// TODO Auto-generated method stub
											if (!CommonUtility.isNull(o)) {
												JSONObject object = (JSONObject) o;
												if (CommonUtility
														.response200(object)) {
													CommonUtility.tip(activity,
															"您已经成功接单");
													JSONObject oo = (JSONObject) getItem(p);
													try {
														oo.getJSONObject(
																"Question")
																.put("Status",
																		2);
													} catch (Exception e) {
														e.printStackTrace();
													}
													LinearLayout ll_zhiliao_huihua = (LinearLayout) view
															.getTag(R.id.tag_obj1);
													ll_zhiliao_huihua
															.setVisibility(View.VISIBLE);
													view.setVisibility(View.GONE);
													try {
														oo.getJSONObject(
																"Question")
																.put("Doctor_Uid",
																		GlobalSettings.sUser.Uid);
														JSONObject jiedan_doctor = oo
																.getJSONObject("Doctor_User");
														jiedan_doctor
																.put("Name",
																		GlobalSettings.sUser.Name);
														jiedan_doctor
																.put("Professional",
																		GlobalSettings.sUser.Professional);
														jiedan_doctor
																.put("Hospital",
																		GlobalSettings.sUser.Hospital);
														oo.put("Doctor_User",
																jiedan_doctor);
														Intent data = new Intent(
																Constant.RECIVER_QUESTION);
														data.putExtra(
																Constant.IDENTITY_KEY,
																oo.toString());
														activity.sendBroadcast(data);

														data = new Intent(
																Constant.RECIVER_CHAT_LIST);
														activity.sendBroadcast(data);
														notifyUpdate();
													} catch (Exception e) {
														e.printStackTrace();
													}
												} else {
													try {
														CommonUtility
																.tip(activity,
																		object.getString("ResultMessage"));
													} catch (Exception e) {
														CommonUtility.tip(
																activity,
																"接单失败");
													}
												}
											}
										}
									}), jieda_params);
				} else {
					activity.startActivity(new Intent(activity,
							LoginActivity.class));
				}
			} else if (id == R.id.btn_guanzhu) {
				if (!CommonUtility.isNull(GlobalSettings.sUser)) {
					final Button btn_guanzhu = (Button) view;
					final int position = (Integer) btn_guanzhu
							.getTag(R.id.tag_obj);
					final boolean isGuanzhu = btn_guanzhu.getText().toString()
							.equals("已关注");
					if (CommonUtility.isNull(params)) {
						params = new HashMap<String, Object>();
						params.put(Constant.PARAM_API, "Follow.Set");
						params.put("method", isGuanzhu ? "cancle" : "add");
						params.put(Constant.PARAM_TOKEN, GlobalSettings.sToken);
					}
					params.put("qids", view.getTag());

					RequestTaskIntercept.requestIntercept(activity,
							Constant.URL.REQUEST, new RequestHandler(activity,
									new HandlerCallback() {

										@Override
										public void callback(Object o) {
											// TODO Auto-generated method
											// stub
											if (!CommonUtility.isNull(o)) {
												JSONObject object = (JSONObject) o;
												if (CommonUtility
														.response200(object)) {
													CommonUtility
															.toast(activity,
																	isGuanzhu ? "取消关注成功"
																			: "关注问题成功");
													btn_guanzhu
															.setText(isGuanzhu ? "关注"
																	: "已关注");
													JSONObject oo = (JSONObject) getItem(position);
													try {
														oo.put("Is_Follow",
																isGuanzhu ? 0
																		: 1);
														int guanzhuNum = oo
																.getInt("FollowerCount");
														oo.put("FollowerCount",
																isGuanzhu ? guanzhuNum - 1
																		: guanzhuNum + 1);
													} catch (Exception e) {
														e.printStackTrace();
													}
													try {
														Intent data = new Intent(
																Constant.RECIVER_QUESTION);
														data.putExtra(
																Constant.IDENTITY_KEY,
																oo.toString());
														activity.sendBroadcast(data);
													} catch (Exception e) {
														// TODO: handle
														// exception
														e.printStackTrace();
													}
												}
											}
										}
									}), params);
				}
			}
		}
	};

	OnClickListener listener_img = new OnClickListener() {

		@Override
		public void onClick(View view) {
			int position = (Integer) view.getTag();
			String[] pics = (String[]) view.getTag(R.id.tag_obj);
			PhotoExtra extra = new PhotoExtra();
			extra.setDisplayedIndex(position);
			extra.setPhotos(OUtil.asArrayList(pics));
			Intent intent = new Intent(activity, PhotoActivity.class);
			extra.putTo(intent);
			activity.startActivity(intent);
		}
	};

}
